(function() {

this.pasta = this.pasta || {};
this.pasta.webgui = this.pasta.webgui || {};

this.pasta.webgui.Edit = pasta.webgui.Control.extend(
{
	init : function() 
	{
		this._super();
		
		this.caption = "";
		
		var id = this.cid;
		
		this.setHeight(18);
		this.password = false;
		
		this.font = new pasta.util.Font();
		this.font.getOnChange().setHandler(this, this.doFontChanged);
		
		this.obj = document.createElement("input");
		this.obj.type = "text";
		this.obj.id = this.cid + "_obj";
		this.obj.style.position = "absolute";
		this.obj.style.left = "0px";
		this.obj.style.top = "0px";
		this.obj.style.width = "100%";
		this.obj.style.height = "100%";
		this.canvas.appendChild(this.obj);
		
		var obj = this;
		this.canvas.onkeydown = function(e) { if (!e) e = window.event; if (window.event) key = e.keyCode; else key = e.which; obj.doKeyDown(key); };
		this.canvas.onkeyup = function(e) { if (!e) e = window.event; if (window.event) key = e.keyCode; else key = e.which; obj.doKeyUp(key); };
		
		this._onKeyDown = null;
	},
	
	//------------------ Event Handler -----------------
	
	doFontChanged : function()
	{
		this.font.applyFont(this.obj);
	},
	
	doKeyDown : function(key)
	{
		if (this._onKeyDown != null)
			this._onKeyDown.callHandler(this, key);
	},
	
	doKeyUp : function(key)
	{
		if (this._onKeyUp != null)
			this._onKeyUp.callHandler(this, key);
	},
	
	//------------------ Setter & Getter -----------------
	
	isEnabled : function(data)
	{
		return (this.obj.disabled == false);
	},
	
	setEnabled : function(data)
	{
		if (data)
			this.obj.disabled = false;
		else
			this.obj.disabled = true;
	},
	
	isReadOnly : function(data)
	{
		return this.obj.readOnly;
	},
	
	setReadOnly : function(data)
	{
		this.obj.readOnly = data;
	},
	
	setFocus : function()
	{
		this.obj.focus();
	},
	
	getText : function()
	{
		return this.obj.value;
	},
	
	setText : function(data)
	{
		this.obj.value = data;
	},
	
	isPassword : function()
	{
		return this.password;
	},
	
	setPassword : function(data)
	{
		this.password = data;
		
		if (this.password)
			this.obj.type = "password";
		else
			this.obj.type = "text";
	},
	
	//--------------------------- Event -------------------------
	
	getOnKeyDown : function()
	{
		if (this._onKeyDown == null)
			this._onKeyDown = new pasta.util.EventObj();
		
		return this._onKeyDown;
	},
	
	getOnKeyUp : function()
	{
		if (this._onKeyUp == null)
			this._onKeyUp = new pasta.util.EventObj();
		
		return this._onKeyUp;
	},
});

})();